package com.my.aslife.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author mayuan
 * @description TODO
 */
public class SerializeUtil {

    private static final class ObjectMapperHolder {
        static final ObjectMapper objectMapper = new ObjectMapper();
    }

    public static String objectMapperToString(Object object) throws JsonProcessingException {
        return ObjectMapperHolder.objectMapper.writeValueAsString(object);
    }

    public static <T> T objectMapperToObject(String val, Class<T> tClass) throws JsonProcessingException {
        return ObjectMapperHolder.objectMapper.readValue(val, tClass);
    }

}
